from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from py_files.router_translate import router as translate_router
from py_files.router_file_translate import router as file_translate_router

# 创建FastAPI应用
app = FastAPI(
    title="深度翻译API",
    description="基于deep_translator库的中英互译API服务",
    version="1.0.0"
)

# 添加CORS中间件
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # 在生产环境中应该限制允许的源
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 添加路由
app.include_router(translate_router, prefix="/translate")
app.include_router(file_translate_router, prefix="/translate/file")

@app.get("/")
async def root():
    return {"message": "see api in /docs"}

# 入口函数
if __name__ == "__main__":
    uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True) 